/*
 * @lc app=leetcode.cn id=504 lang=cpp
 *
 * [504] 七进制数
 */

// @lc code=start
class Solution
{
public:
  string convertToBase7(int num)
  {
    if (num == 0) return "0";
    string ans;
    int abs_num = abs(num);
    while (abs_num != 0) {
      ans.push_back(abs_num % 7 + '0');
      abs_num /= 7;
    }
    if (num < 0)
      ans.push_back('-');
    reverse(ans.begin(), ans.end());
    return ans;
  }
};
// @lc code=end
